package com.haohao.web.controller.product.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.haohao.common.annotation.Log;
import com.haohao.common.core.controller.BaseController;
import com.haohao.common.core.domain.AjaxResult;
import com.haohao.common.core.page.TableDataInfo;
import com.haohao.common.enums.BusinessType;
import com.haohao.common.utils.poi.ExcelUtil;
import com.haohao.web.controller.product.domain.TProducts;
import com.haohao.web.controller.product.service.ITProductsService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 产品信息Controller
 * 
 * @author ruoyi
 * @date 2024-04-18
 */
@RestController
@RequestMapping("/product/products")
public class TProductsController extends BaseController
{
    @Autowired
    private ITProductsService tProductsService;

    /**
     * 查询产品信息列表
     */
    @PreAuthorize("@ss.hasPermi('product:products:list')")
    @GetMapping("/list")
    public TableDataInfo list(TProducts tProducts)
    {
        startPage();
        List<TProducts> list = tProductsService.selectTProductsList(tProducts);
        return getDataTable(list);
    }

    /**
     * 导出产品信息列表
     */
    @PreAuthorize("@ss.hasPermi('product:products:export')")
    @Log(title = "产品信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TProducts tProducts)
    {
        List<TProducts> list = tProductsService.selectTProductsList(tProducts);
        ExcelUtil<TProducts> util = new ExcelUtil<TProducts>(TProducts.class);
        util.exportExcel(response, list, "产品信息数据");
    }

    /**
     * 获取产品信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:products:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tProductsService.selectTProductsById(id));
    }

    /**
     * 新增产品信息
     */
    @PreAuthorize("@ss.hasPermi('product:products:add')")
    @Log(title = "产品信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TProducts tProducts)
    {
        return toAjax(tProductsService.insertTProducts(tProducts));
    }

    /**
     * 修改产品信息
     */
    @PreAuthorize("@ss.hasPermi('product:products:edit')")
    @Log(title = "产品信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TProducts tProducts)
    {
        return toAjax(tProductsService.updateTProducts(tProducts));
    }

    /**
     * 删除产品信息
     */
    @PreAuthorize("@ss.hasPermi('product:products:remove')")
    @Log(title = "产品信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tProductsService.deleteTProductsByIds(ids));
    }
}
